home *** CD-ROM | disk | FTP | other *** search
/ Internet Pratica / IPRAT_01.iso / ASP / ASPapp Portal / submit.asp < prev    next >
Encoding:
Text File  |  2002-03-12  |  10.9 KB  |  388 lines

  1. <!-- #include file="i_utils.asp" -->
  2. <%
  3.  
  4. check_security(1) 
  5.  
  6. %>
  7. <%
  8.     dim receipt_text
  9.     dim success
  10.     dim DateAdded
  11.     dim LinkID
  12.     dim user_id
  13.     dim Title
  14.     dim URL
  15.     dim CatID
  16.     dim LinkTypeID
  17.     dim Description
  18.     dim DownloadURL
  19.     dim DownloadFee
  20.     dim Email
  21.     dim SUBMIT
  22.     dim add_link_sql
  23.  
  24. sub request_add_link
  25. ''' request expected input parameters for this form
  26.     DateAdded = request("DateAdded")
  27.     LinkID = request("LinkID")
  28.     user_id = request("user_id")
  29.     Title = request("Title")
  30.     URL = request("URL")
  31.     CatID = request("CatID")
  32.     LinkTypeID = request("LinkTypeID")
  33.     Description = request("Description")
  34.     DownloadURL = request("DownloadURL")
  35.     DownloadFee = request("DownloadFee")
  36.     Email = request("Email")
  37.     SUBMIT = request("SUBMIT")
  38. end sub
  39.  
  40. sub validate_add_link
  41. ''' request and validate data entered from this form
  42.     DateAdded = trim(request("DateAdded"))
  43.     if DateAdded = "" then
  44.         error_list.add "484202","DateAdded must be specified."
  45.         b_error = true
  46.     end if
  47.     if DateAdded <> "" AND (not isdate(DateAdded)) then
  48.         error_list.add "484202date","DateAdded must be a valid date (MM/DD/YY)."
  49.         b_error = true
  50.     end if
  51.     LinkID = trim(request("LinkID"))
  52.     user_id = trim(request("user_id"))
  53.     if user_id = "" then
  54.         error_list.add "484212","user_id must be specified."
  55.         b_error = true
  56.     end if
  57.     Title = trim(request("Title"))
  58.     if Title = "" then
  59.         error_list.add "484210","Site Title must be specified."
  60.         b_error = true
  61.     end if
  62.     URL = trim(request("URL"))
  63.     if URL = "" then
  64.         error_list.add "484211","URL must be specified."
  65.         b_error = true
  66.     end if
  67.     CatID = trim(request("CatID"))
  68.     if CatID = "" then
  69.         error_list.add "484213","Category must be specified."
  70.         b_error = true
  71.     end if
  72.     LinkTypeID = trim(request("LinkTypeID"))
  73.     if LinkTypeID = "" then
  74.         error_list.add "484208","Resource Type must be specified."
  75.         b_error = true
  76.     end if
  77.     Description = trim(request("Description"))
  78.     if Description = "" then
  79.         error_list.add "484203","Description must be specified."
  80.         b_error = true
  81.     end if
  82.     DownloadURL = trim(request("DownloadURL"))
  83.     DownloadFee = trim(request("DownloadFee"))
  84.     Email = trim(request("Email"))
  85.     if Email = "" then
  86.         error_list.add "484206","Email must be specified."
  87.         b_error = true
  88.     end if
  89.     SUBMIT = trim(request("SUBMIT"))
  90. end sub
  91.  
  92. sub get_defaults_add_link
  93. ''' set default values for this form
  94.     DateAdded = "" & now() & ""
  95.     user_id = session("user_id")
  96.     SUBMIT = "SUBMIT"
  97. end sub
  98.  
  99. sub db_select_add_link
  100.     sql = "SELECT " & _ 
  101.     "DateAdded, " & _ 
  102.     "LinkID, " & _ 
  103.     "user_id, " & _ 
  104.     "Title, " & _ 
  105.     "URL, " & _ 
  106.     "CatID, " & _ 
  107.     "LinkTypeID, " & _ 
  108.     "Description, " & _ 
  109.     "DownloadURL, " & _ 
  110.     "DownloadFee, " & _ 
  111.     "Email FROM Links" & _ 
  112.     " WHERE " & _ 
  113.     "Links.LinkID = " & to_sql(LinkID,"number") & ""
  114.     on error resume next
  115.     set rs = cn.Execute(sql)
  116.     if err.number <> 0 then
  117.         b_error = true
  118.         error_list.add "select_data_add_link", "The data selection failed. " & err.description
  119.     elseif rs.EOF then
  120.         b_results = false
  121.         msg_list.add "select_data_add_link", "The record was removed from the database."
  122.     else
  123.         DateAdded = rs("DateAdded")
  124.         LinkID = rs("LinkID")
  125.         user_id = rs("user_id")
  126.         Title = rs("Title")
  127.         URL = rs("URL")
  128.         CatID = rs("CatID")
  129.         LinkTypeID = rs("LinkTypeID")
  130.         Description = rs("Description")
  131.         DownloadURL = rs("DownloadURL")
  132.         DownloadFee = rs("DownloadFee")
  133.         Email = rs("Email")
  134.         SUBMIT = rs("SUBMIT")
  135.     end if
  136.     rs.Close
  137.     on error goto 0
  138. end sub
  139. sub db_insert_add_link
  140.     sql = "INSERT INTO Links" & _ 
  141.     "(" & _ 
  142.     "CatID," & _ 
  143.     "DateAdded," & _ 
  144.     "Description," & _ 
  145.     "DownloadFee," & _ 
  146.     "DownloadURL," & _ 
  147.     "Email," & _ 
  148.     "LinkTypeID," & _ 
  149.     "Title," & _ 
  150.     "URL," & _ 
  151.     "display," & _ 
  152.     "user_id" & _ 
  153.     ") VALUES (" & _ 
  154.     "" & to_sql(CatID,"number") & "," & _ 
  155.     "" & to_sql(DateAdded,"text") & "," & _ 
  156.     "" & to_sql(Description,"text") & "," & _ 
  157.     "" & to_sql(DownloadFee,"text") & "," & _ 
  158.     "" & to_sql(DownloadURL,"text") & "," & _ 
  159.     "" & to_sql(Email,"text") & "," & _ 
  160.     "" & to_sql(LinkTypeID,"number") & "," & _ 
  161.     "" & to_sql(Title,"text") & "," & _ 
  162.     "" & to_sql(URL,"text") & "," & _ 
  163.     "0," & _ 
  164.     "" & to_sql(user_id,"number") & ")" & _ 
  165.     ""
  166.     'response.write sql
  167.     on error resume next
  168.     cn.Execute(sql)
  169.     if err.Number <> 0 then
  170.         b_error = true
  171.         error_list.add "db_insert_add_link" & err.Number ,"The database insert failed. " & err.Description
  172.     else
  173.         set rs = cn.Execute("SELECT @@IDENTITY")
  174.         LinkID = rs(0)
  175.         rs.Close
  176.         msg_list.add "db_insert_add_link","The database insert was successful."    end if
  177.     on error goto 0
  178. end sub
  179. sub db_update_add_link
  180.     sql = "UPDATE Links SET " & _ 
  181.     "DateAdded = " & to_sql(DateAdded,"text") & ", " & _ 
  182.     "user_id = " & to_sql(user_id,"number") & ", " & _ 
  183.     "Title = " & to_sql(Title,"text") & ", " & _ 
  184.     "URL = " & to_sql(URL,"text") & ", " & _ 
  185.     "CatID = " & to_sql(CatID,"number") & ", " & _ 
  186.     "LinkTypeID = " & to_sql(LinkTypeID,"number") & ", " & _ 
  187.     "Description = " & to_sql(Description,"text") & ", " & _ 
  188.     "DownloadURL = " & to_sql(DownloadURL,"text") & ", " & _ 
  189.     "DownloadFee = " & to_sql(DownloadFee,"text") & ", " & _ 
  190.     "Email = " & to_sql(Email,"text") & " WHERE " & _ 
  191.     "LinkID = " & to_sql(LinkID,"number") & ""
  192.     'response.write sql
  193.     on error resume next
  194.     cn.execute(sql)
  195.     if err.number <> 0 then
  196.         b_error = true
  197.         error_list.add "db_update_add_link" & err.Number ,"The database update failed. " & err.Description
  198.     else
  199.         msg_list.add "db_update_add_link" & LinkID,"The database update was successful."
  200.     end if
  201.     on error goto 0
  202. end sub
  203. sub db_delete_add_link
  204.     sql = "DELETE FROM Links" & _ 
  205.     " WHERE " & _ 
  206.     "LinkID = " & to_sql(LinkID,"number") & ""
  207.     'response.write sql
  208.     on error resume next
  209.     cn.Execute(sql)
  210.     if err.number <> 0 then
  211.         b_error = true
  212.         error_list.add "db_delete_add_link" & err.Number ,"The database deletion failed. " & err.Description
  213.     else
  214.         msg_list.add "db_delete_add_link","The record was removed."
  215.     end if
  216.     on error goto 0
  217. end sub
  218.  
  219. do_search = request("do_search")
  220. ''' request form keys
  221. receipt_text = request("receipt_text")
  222. success = request("success")
  223. LinkID = request("LinkID")
  224. ''' request action
  225. action = lcase(request("action"))
  226. ''' action case handler
  227. select case action
  228.  
  229. case "select_add_link"
  230. '  select the requested key record from database
  231. if LinkID <> "" then
  232.     db_select_add_link
  233. else
  234.     b_error = true
  235.     error_list.add "edit_add_link", "Specify record to select."
  236. end if
  237.  
  238.  
  239. case "insert_add_link"
  240. '  request form data and insert a new record into database
  241.  
  242. validate_add_link
  243. if not b_error then
  244.     db_insert_add_link
  245.     if not b_error then response.redirect "submit.asp?success=1"
  246. end if
  247.  
  248.  
  249.  
  250. case "update_add_link"
  251. '  request form data and update an existing database record
  252. validate_add_link
  253. if not b_error then
  254. if LinkID <> "" then
  255.     db_update_add_link
  256. else
  257.     b_error = true
  258.     error_list.add "update_add_link", "Specify record to update."
  259. end if
  260. end if
  261.  
  262.  
  263. case "delete_add_link"
  264. '  delete the requested key database record
  265. if LinkID <> "" then
  266.     db_delete_add_link
  267.     response.redirect request.servervariables("script_name") & "?msg=The+record+was+deleted."
  268. else
  269.     b_error = true
  270.     error_list.add "delete_add_link", "Specify record to delete."
  271. end if
  272.  
  273.  
  274. end select
  275.  
  276. '  no action was specified, so handle the default case(s)
  277. if receipt_text <> "" AND success <> "" then
  278.     db_select_receipt_text
  279. end if
  280.  
  281. if LinkID <> "" then
  282.     db_select_add_link
  283. else
  284.     get_defaults_add_link
  285. end if
  286.  
  287.  
  288. %>
  289.  
  290. <!-- #include file='i_header.asp' -->
  291. <!-- #include file='i_menu.asp' -->
  292.  
  293.  
  294. <%
  295. display_errs
  296. display_msg
  297. %>
  298.  
  299. <% if success = 1 then %>
  300. <!-- display receipt text -->
  301.         <ul>
  302.  
  303. Thanks for submitting your site. It will be reviewed for inclusion in our links section.
  304.  
  305. </ul>
  306.         
  307.  
  308.  
  309. <% else %>
  310. <!-- display the submit form -->
  311. <% CatId = request("CatId") %>
  312. <table class='headerTable'>
  313. <tr>
  314. <td class='headerTD'>
  315. Suggest your site
  316. </td>
  317. </tr>
  318. </table>
  319. <table  style={width:'100%';}>
  320. <form name="add_link" action="submit.asp" method="post" >
  321.         
  322.         <input type=hidden name="DateAdded" value="<% =DateAdded %>">
  323.         
  324.         
  325.         <input type=hidden name="LinkID" value="<% =LinkID %>">
  326.         
  327.         
  328.         <input type=hidden name="user_id" value="<% =user_id %>">
  329.         
  330. <tr>
  331.     <td class='labelTD'>Site Title</td>
  332.     <td class='dataTD' >
  333.         <input type=text  name="Title" size="" maxlength="60" value="<% =Title%>">
  334.     </td>
  335.     <td class='labelTD'></td>
  336. </tr>
  337. <tr>
  338.     <td class='labelTD'>URL</td>
  339.     <td class='dataTD' >
  340.         <input type=text  name="URL" size="" maxlength="100" value="<% =URL%>">
  341.     </td>
  342.     <td class='labelTD'></td>
  343. </tr>
  344. <tr>
  345.     <td class='labelTD'>Category</td>
  346.     <td class='dataTD' >
  347.         
  348.         <select name="CatID" >
  349.         <option></option>
  350.         <%
  351.          =get_options ("SELECT Cats3.CatId, Cats.Cat, Cats1.Cat, Cats2.Cat, Cats3.Cat FROM (((Cats As Cats3 left JOIN Cats As Cats2 ON Cats3.ParentId = Cats2.CatId) left JOIN Cats As Cats1 ON Cats2.ParentId = Cats1.CatId) LEFT JOIN Cats As Cats ON Cats1.ParentId = Cats.CatId) WHERE Cats.ParentId is NULL order by (Cats.Cat + Cats1.Cat + Cats2.Cat + Cats3.Cat)", CatID) 
  352.         %>
  353.         </select>
  354.         
  355.     </td>
  356.     <td class='labelTD'></td>
  357. </tr>
  358. <tr>
  359.     <td class='labelTD'>Resource Type</td>
  360.     <td class='dataTD' >
  361.         
  362.         <select name="LinkTypeID" >
  363.         
  364.         <%
  365.          =get_options ("SELECT LinkTypeID, LinkType FROM LinkTypes", LinkTypeID) 
  366.         %>
  367.         </select>
  368.         
  369.     </td>
  370.     <td class='labelTD'></td>
  371. </tr>
  372. <tr>
  373.     <td class='labelTD'>Description</td>
  374.     <td class='dataTD' >
  375.         
  376.         <textarea  name="Description" rows='5' cols='60'><% =Description%></textarea>
  377.         
  378.     </td>
  379.     <td class='labelTD'>upto 100 words - no HTML!</td>
  380. </tr>
  381. <tr>
  382.     <td class='labelTD'>Download URL</td>
  383.     <td class='dataTD' >
  384.         <input type=text  name="DownloadURL" size="" maxlength="100" value="<% =DownloadURL%>">
  385.     </td>
  386.     <td class='labelTD'>if you product is downloadable, specify the download url</td>
  387. </tr>
  388. <tr>
  389.     <td class='labelTD'>Minimum Cost/Fee</td>
  390.     <td class='dataTD' >
  391.         <input type=text  name="DownloadFee" size="" maxlength="40" value="<% =DownloadFee%>">
  392.     </td>
  393.     <td class='labelTD'>if you sell products or services on your site, what is the minimum cost?</td>
  394. </tr>
  395. <tr>
  396.     <td class='labelTD'>Email</td>
  397.     <td class='dataTD' >
  398.         <input type=text  name="Email" size="" maxlength="50" value="<% =Email%>">
  399.     </td>
  400.     <td class='labelTD'>used for aspapp.com internal use only</td>
  401. </tr>
  402. <tr>
  403.     <td class='labelTD'></td>
  404.     <td class='dataTD' >
  405.         <input class=cmd  type=submit name="SUBMIT" value="SUBMIT" >
  406.     </td>
  407.     <td class='labelTD'></td>
  408. </tr>
  409. <tr>
  410.     <td class=labelTD align=right> 
  411.     <% if LinkID <> "" then %><% end if %>
  412.     </td>
  413.     <td class=dataTD>
  414.     <% if LinkID = "" then %><% end if %>
  415.     </td>
  416.     <td class=labelTD> 
  417.     </td>
  418. <input type=hidden name="action" value="<% if LinkID <> "" then %>update<% else %>insert<%end if %>_add_link"></tr>
  419.  
  420. </form>
  421. </table>
  422.  
  423. <% end if %>
  424.  
  425. <!-- #include file=i_footer.asp -->
  426.  
  427.  
  428. <%
  429. ':: assure that any db resources are freed
  430. on error resume next
  431. rs.Close
  432. set rs = NOTHING
  433. cn.Close
  434. set cn = NOTHING
  435. user_cn.Close
  436. set user_cn = NOTHING
  437. on error goto 0
  438. %>
  439.